package ui;

import java.awt.BorderLayout;
import java.awt.Point;

import javax.swing.JPanel;
import javax.swing.JFrame;
import javax.swing.JInternalFrame;
import java.awt.Dimension;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import java.awt.Rectangle;
import java.util.Iterator;
import javax.swing.JDesktopPane;
import javax.swing.JComboBox;
import javax.swing.JButton;

import dominio.Contenedora;
import dominio.Zona;

public class UISelectZona extends javax.swing.JDialog  {

	private static final long serialVersionUID = 1L;

	private JPanel jContentPane = null;

	private JLabel jLabel = null;

	private JComboBox cmbzona = null;

	private JButton btnaceptar = null;
	
	private Zona zonaSeleccionada;
	
	private boolean opcionTodos;

	/**
	 * This is the default constructor
	 */
	public UISelectZona(boolean todos) {
		super();
		this.opcionTodos = todos;
		initialize();
	}

	public Zona getZonaSeleccionada() {
		return zonaSeleccionada;
	}

	public void setZonaSeleccionada(Zona zonaSeleccionada) {
		this.zonaSeleccionada = zonaSeleccionada;
	}
	
	/**
	 * This method initializes this
	 * 
	 * @return void
	 */
	private void initialize() {
		this.setSize(380, 91);
		//this.setClosable(true);
		this.setIconImage(java.awt.Toolkit.getDefaultToolkit().createImage(getClass().getResource("/imagenes/iconordenar.gif")));
		this.setContentPane(getJContentPane());
		this.setTitle("Seleccionar Zona");
		Zona unaZona;
		if(opcionTodos){
			unaZona = new Zona();
			unaZona.setId(0);
			unaZona.setDescripcion("Todas");
			cmbzona.addItem(unaZona);
		}
		
		Iterator it = Contenedora.getInstancia().obtenerZonas().iterator();
		while (it.hasNext()){
			unaZona = (Zona) it.next();	
			cmbzona.addItem(unaZona);
		}
	}

	/**
	 * This method initializes jContentPane
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getJContentPane() {
		if (jContentPane == null) {
			jLabel = new JLabel();
			jLabel.setBounds(new Rectangle(14, 22, 38, 16));
			jLabel.setText("Zona:");
			jContentPane = new JPanel();
			jContentPane.setLayout(null);
			jContentPane.add(jLabel, null);
			jContentPane.add(getCmbzona(), null);
			jContentPane.add(getBtnaceptar(), null);
		}
		return jContentPane;
	}

	/**
	 * This method initializes cmbzona	
	 * 	
	 * @return javax.swing.JComboBox	
	 */
	private JComboBox getCmbzona() {
		if (cmbzona == null) {
			cmbzona = new JComboBox();
			cmbzona.setBounds(new Rectangle(55, 19, 191, 22));
		}
		return cmbzona;
	}

	/**
	 * This method initializes btnaceptar	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getBtnaceptar() {
		if (btnaceptar == null) {
			btnaceptar = new JButton();
			btnaceptar.setBounds(new Rectangle(255, 13, 106, 35));
			btnaceptar.setIcon(new ImageIcon(getClass().getResource("/imagenes/aceptar.jpg")));
			btnaceptar.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					setZonaSeleccionada((Zona)cmbzona.getSelectedItem());
					hide();
				}
			});
		}
		return btnaceptar;
	}



}  //  @jve:decl-index=0:visual-constraint="10,10"
